<?php

namespace IDock\Insurance\YAIC\Response;

use IDock\Http\Response;
use IDock\Printer\NonCar\NonCarProductListPrinter;
use IDock\Printer\NonCar\NonCarProductPrinter;
use IDock\Printer\NonCar\NonCarSubCoveragePrinter;

class NonCarProductListResponse extends AllYAICResponse
{
    /**
     * @var NonCarProductListPrinter $printer
     */
    public $printer = NonCarProductListPrinter::class;

    public function printerInit(): Response
    {
        $printer = new NonCarProductListPrinter();

        $list = [
            [
                'productCode' => '20250718251A1',
                'productName' => '单座基础版-49元（单司机）',
                'planCode' => '20250718251A1',
                'planName' => '单座基础版-49元（单司机）',
                'premium' => '49',
                'maxLimit' => '1',
                'coverageList' => [
                    [
                        'subCode' => '',
                        'subName' => '意外身故、残疾',
                        'amount' => '50000',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '意外伤害医疗',
                        'amount' => '5000',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '意外伤害住院津贴',
                        'amount' => '50/天',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '节假日及双休日意外伤害',
                        'amount' => '50000',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '救护车费用',
                        'amount' => '500',
                        'premium' => '',
                    ],
                ],
            ],
            [
                'productCode' => '20250718251B1',
                'productName' => '单座基础版-79元（单司机）',
                'planCode' => '20250718251B1',
                'planName' => '单座基础版-79元（单司机）',
                'premium' => '79',
                'maxLimit' => '1',
                'coverageList' => [
                    [
                        'subCode' => '',
                        'subName' => '意外身故、残疾',
                        'amount' => '100000',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '意外伤害医疗',
                        'amount' => '10000',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '意外伤害住院津贴',
                        'amount' => '50/天',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '节假日及双休日意外伤害',
                        'amount' => '100000',
                        'premium' => '',
                    ],
                    [
                        'subCode' => '',
                        'subName' => '救护车费用',
                        'amount' => '800',
                        'premium' => '',
                    ],
                ],
            ],
        ];

        foreach ($list as $item) {
            $amount = 0;
            $productPrinter = new NonCarProductPrinter();
            $productPrinter->productCode = $item['productCode'] ?? '';//产品编码
            $productPrinter->productName = $item['productName'] ?? '';//产品名称
            $productPrinter->productType = '驾意险';
            $productPrinter->productDesc = '';
            $productPrinter->planCode = $item['planCode'] ?? '';//方案代码
            $productPrinter->planName = $item['planName'] ?? '';//方案名称
            $productPrinter->maxQuantity = $item['maxLimit'];//最大购买份数
            foreach ($item['coverageList'] ?? [] as $sub) {
                $subCoverage = new NonCarSubCoveragePrinter();
                $subCoverage->subCode = $sub['subCode'] ?? '';
                $subCoverage->subName = $sub['subName'] ?? '';
                $subCoverage->amount = $sub['amount'] ?? '';
                if ($subCoverage->subName != '意外伤害住院津贴') {
                    $amount += $subCoverage->amount;
                }
                $productPrinter->subCoverageAppend($subCoverage);
            }
            $productPrinter->premium = $item['premium'];
            $productPrinter->unitAmount = $amount;
            $productPrinter->argc['amount'] = $amount;
            $productPrinter->argc['productName'] = $item['productName'] ?? '';//产品名称

            $printer->productListAppend($productPrinter);
        }


        $this->printer = $printer;
        return $this;
    }
}
